package com.example.photograph.controller;

import com.example.photograph.domain.SysMenu;
import com.example.photograph.domain.SysNotice;
import com.example.photograph.domain.SysUser;
import com.example.photograph.service.ISysMenuService;
import com.example.photograph.service.ISysNoticeService;
import com.example.photograph.service.ISysUserService;
import com.example.photograph.utils.ShiroUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;

import java.util.List;

/**
 * 首页 业务处理
 * 
 * @author wuyj
 */
@Controller
public class SysIndexController extends BaseController
{
    @Autowired
    private ISysMenuService menuService;
    @Autowired
    private ISysNoticeService iSysNoticeService;
    @Autowired
    private ISysUserService iSysUserService;

    // 系统首页
    @GetMapping("/index")
    public String index(ModelMap mmap)
    {
        // 取身份信息
        SysUser user = ShiroUtils.getSysUser();
        // 根据用户id取出菜单
        List<SysMenu> menus = menuService.selectMenusByUser(user);
        mmap.put("menus", menus);
        mmap.put("user", user);
        return "index";
    }

    // 切换主题
    @GetMapping("/system/switchSkin")
    public String switchSkin(ModelMap mmap)
    {
        return "skin";
    }

    // 系统介绍
    @GetMapping("/system/main")
    public String main(ModelMap mmap)
    {
        Long userId = ShiroUtils.getUserId();
        SysUser user = iSysUserService.selectUserById(userId);

        SysNotice noticeParam = new SysNotice();
        noticeParam.setStatus("1");
        noticeParam.setNoticeType("2");
        List<SysNotice> noticeList = iSysNoticeService.selectNoticeList(noticeParam);

        SysNotice informParam = new SysNotice();
        informParam.setStatus("1");
        informParam.setNoticeType("1");
        if ("client".equals(user.getRole().getRoleKey()) || null == user.getRole()){
            informParam.setUserId(userId);
        }
        List<SysNotice> informList = iSysNoticeService.selectNoticeList(informParam);
        mmap.put("noticeList",noticeList);
        mmap.put("informList",informList);
        return "main";
    }
}
